package cqut.wys;

import org.java_websocket.WebSocketImpl;

import java.net.URI;
import java.net.URISyntaxException;

/**
 * WebSocket客户端
 * @author wuyoushan@zbj.com
 * @date 2017/3/15.
 */
public class Client
{
    private static final String URL="ws://localhost:8189";

    public static void main( String[] args ) throws URISyntaxException{
        //以调试的方式打印出对应的数据，默认为false
        WebSocketImpl.DEBUG = true;
        WebClient webClient=new WebClient(new URI(URL));
        //打开连接
        webClient.connect();

        while (true){
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
                System.out.println("出现线程中断错误");
            }
            if(webClient!=null){
                webClient.send("Hello WebSocket");
                System.out.println("发送消息为:\tHello WebSocket");
            }else {
                webClient.connect();
            }
        }
    }
}
